Micron Document
Deavmi's coding shack

Node / mirrors / glog / commits / a6fbc10

Commit a6fbc10f4b099608af0b1c077966676cbc3400a3


Parents : 6f310a2
Author : Tristan Brice Velloza Kildaire <deavmi@redxen.eu>
Date : 2026-04-27T18:39:08+02:00

docs

Changes

1 files changed, 29 insertions(+), 15 deletions(-)

M record/type.go +29 -15

Diff

diff --git a/record/type.go b/record/type.go
index f051acd..0ba641c 100644
--- a/record/type.go
+++ b/record/type.go
@@ -1,10 +1,17 @@
-package record;
+package record
-import "fmt";
-import "strings";
+import (
+ "fmt"
+ "strings"
+)
+// represents a LogRecord
+//
+// this is how ALL log messages are
+// modeled, effectively as a key-value
+// mapping
type LogRecord struct {
- _data map[any]any; // TODO: Lock? I mean why would you have multiple ppeople editing the same record, seems odd
+ _data map[any]any // TODO: Lock? I mean why would you have multiple ppeople editing the same record, seems odd
}
// clones
@@ -19,36 +26,40 @@ func (lr LogRecord) Clone() LogRecord {
// returns a list of all the keys
func (lr *LogRecord) Keys() []any {
- var keys_cpy []any;
- for k, _ := range(lr._data) {
+ var keys_cpy []any
+ for k, _ := range lr._data {
keys_cpy = append(keys_cpy, k)
}
- return keys_cpy;
+ return keys_cpy
}
-
// performs nil-checks and RTTI comparability checks
//
// call this whenever consuming a key
func kCheck(key any) {
if key == nil {
- panic("Key cannot be null");
- }
+ panic("Key cannot be null")
+ }
// TODO: Perform RTTI check for comparable `key`
}
+// sets the entry's value
func (lr *LogRecord) Set(key any, value any) {
kCheck(key)
lr._data[key] = value
}
+// checks if the entry exists
func (lr LogRecord) Has(key any) bool {
kCheck(key)
var _, ok = lr._data[key]
- return ok;
+ return ok
}
+// obtains the entry's value,
+// returning an error if it does
+// not exist
func (lr LogRecord) Get(key any) (any, error) {
kCheck(key)
@@ -59,7 +70,10 @@ func (lr LogRecord) Get(key any) (any, error) {
}
}
-func (lr *LogRecord) Remove(key any) (error) {
+// removes the given entry,
+// returning an error if it does
+// not exist
+func (lr *LogRecord) Remove(key any) error {
kCheck(key)
if !lr.Has(key) {
@@ -73,13 +87,13 @@ func (lr *LogRecord) Remove(key any) (error) {
// Define String() functionality to implement
// the Stringer interface
func (lr LogRecord) String() string {
- var s string;
- for k, v := range(lr._data) {
+ var s string
+ for k, v := range lr._data {
fmt.Printf("Seen key %s with value %s\n", k, v)
s = s + fmt.Sprintf("%s=%s,", k, v)
}
- s=strings.TrimRight(s, ",")
+ s = strings.TrimRight(s, ",")
return s
}

Served by rngit 1.5.0 - Generated in 0.05s